<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
        <title>Document</title>
        <script>
            window.onload = function(){
                var oUl = document.getElementById("ul1");
                var aLis = oUl.getElementsByTagName("li");

                //添加点击事件
                for(var i = 0; i < aLis.length; i++){
                    aLis[i].onclick = function(){
                        this.style.backgroundColor = 'red';
                    }
                }

                var obtn = document.getElementById("btn1");
                var i = 6;
                obtn.onclick = function(){
                    var newNode = document.createElement("li");
                    newNode.innerHTML = i++ * 1111;
                    oUl.appendChild(newNode);
                }
            }

            /* 
                1、浪费
                2、后添加的节点没有点击事件
            */
        </script>
    </head>
    <body>
        <button id = 'btn1'>新增节点</button>
        <ul id = 'ul1'>
            <li>1111</li>
            <li>2222</li>
            <li>3333</li>
            <li>4444</li>
            <li>5555</li>
        </ul>
    </body>
</html>